// 初始化场景、相机和渲染器
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// 加载GLTF模型
const loader = new THREE.GLTFLoader();
loader.load('path/to/your/model.gltf', function(gltf) {
    scene.add(gltf.scene);
}, undefined, function(error) {
    console.error(error);
});

// 初始化Raycaster和鼠标向量
const raycaster = new THREE.Raycaster();
const mouse = new THREE.Vector2();

// 鼠标移动事件监听器
function onMouseMove(event) {
    // 计算鼠标在屏幕上的位置，并转换为标准化设备坐标(NDC)
    mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
    mouse.y = -(event.clientY / window.innerHeight) * 2 + 1;
}

window.addEventListener('mousemove', onMouseMove, false);

// 渲染循环
function animate() {
    requestAnimationFrame(animate);

    // 更新Raycaster
    raycaster.setFromCamera(mouse, camera);

    // 检查鼠标下的对象
    const intersects = raycaster.intersectObjects(scene.children, true);

    if (intersects.length > 0) {
        // 处理悬浮逻辑
        // 例如：intersects[0].object.material.color.set(0xff0000);
    }

    renderer.render(scene, camera);
}

animate();